<!--
 * @Description: 定制功能帘
 * 
 * @Author: XiongYaoYuan<xiongyaoyuan>
 * @Date: 2023-05-09 11:12:07
 * @FilePath: /yuxiuproweb/src/views/goods/use/index.vue
-->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="品名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入品名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['md:id:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['md:id:remove']"
          >删除</el-button
        >
      </el-col>
      
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="idList"
      @selection-change="handleSelectionChange"
      :max-height="maxHeight"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="品名" align="center" prop="name" width="160" />
      <el-table-column label="销售型号" align="center" prop="salesModel" />
      <el-table-column label="销售别名" align="center" prop="salesAlias" />
      <el-table-column label="采购方式" align="center" prop="procurementMethod">
        <template slot-scope="{ row }">
          {{
            row.procurementMethod === "0"
              ? "自生产"
              : row.procurementMethod === "1"
              ? "外采购"
              : row.procurementMethod === "2"
              ? "标品"
              : ""
          }}
        </template>
      </el-table-column>
      <el-table-column label="最小起算" align="center" prop="minimum" />
      <el-table-column label="单重" align="center" prop="pieceWeight" />
      <el-table-column label="是否启用" align="center" prop="enableFlag">
        <template slot-scope="{ row }">
          {{ row.enableFlag === "Y" ? "是" : "否" }}
        </template>
      </el-table-column>
      <el-table-column label="销售信息" align="center" prop="marketingInfo" />
      <el-table-column label="加工信息" align="center" prop="processInfo" />
      <el-table-column label="sku图" align="center" prop="skuPicture" />
      <el-table-column label="价格模型" align="center" prop="priceModel">
        <template slot-scope="{ row }">{{
          row.priceModel === "0"
            ? "默认"
            : row.priceModel === "1"
            ? "布按米"
            : row.priceModel === "2"
            ? "布按套"
            : ""
        }}</template>
      </el-table-column>
      <el-table-column label="出厂价" align="center" prop="factoryPrice" />
      <el-table-column label="经销价" align="center" prop="wholesalePrice" />
      <el-table-column label="零售价" align="center" prop="retailPrice" />
      <el-table-column
        label="APP展示内容维护"
        align="center"
        min-width="130"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <!-- v-hasPermi="['md:curtain:edit']" -->
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleMaintenance(scope.row)"
            >维护</el-button
          >
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        min-width="130"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['md:id:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['md:id:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改定制功能帘对话框 -->
    <add-view
      v-if="open.show"
      :show.sync="open.show"
      v-bind="open"
      @update="getList"
    ></add-view>

    <!-- app图片维护 -->
    <image-view
      v-if="image.show"
      :show.sync="image.show"
      v-bind="image"
      @update="getList"
    ></image-view>
  </div>
</template>

<script>
import { listOtherCurtain, delOtherCurtain } from "@/api/goods/use";
import AddView from "./mods/add.vue";
import ImageView from "@/views/app/image/mods/add.vue";
import commonMix from "@/utils/mixins/common";

export default {
  mixins: [commonMix],
  components: {
    AddView,
    ImageView,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 定制功能帘表格数据
      idList: [],
      // 是否显示弹出层
      open: {
        show: false,
        type: "add",
        data: null,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        name: null,
      },
      // app相关
      image: {
        show: false,
        type: "3",
        id: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询定制功能帘列表 */
    getList() {
      this.loading = true;
      listOtherCurtain(this.queryParams).then((response) => {
        this.idList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.otherCurtainId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = {
        show: true,
        type: "add",
        data: null,
      };
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.open = {
        show: true,
        type: "edit",
        data: {
          ...row,
        },
      };
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const otherCurtainIds = row.otherCurtainId || this.ids;
      this.$modal
        .confirm(
          '是否确认删除定制功能帘编号为"' + otherCurtainIds + '"的数据项？'
        )
        .then(function () {
          return delOtherCurtain(otherCurtainIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 维护app数据 */
    handleMaintenance({ otherCurtainId }) {
      this.image = {
        show: true,
        type: "3",
        id: otherCurtainId,
      };
    },
  },
};
</script>
